package com.anolesoft.yr.mbus.pre.mapper;

import com.anolesoft.yr.mbus.pre.dto.PrePromoteDeleteDTO;
import com.anolesoft.yr.mbus.pre.dto.PrePromoteSaveDTO;
import com.anolesoft.yr.mbus.pre.dto.PrePromoteUpdateDTO;
import com.anolesoft.yr.mbus.pre.sql.PrePromoteSQL;
import com.anolesoft.yr.mbus.pre.vo.PrePromoteQueryVO;
import com.anolesoft.yr.mbus.pre.vo.PrePromoteQueryVO2;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrePromoteMapper {

    //新增时查询推广记录编号是否已经存在
    @Select(PrePromoteSQL.QUERY_PRE_PROMOTE_BY_CODE)
    @Results(id = "queryPromoteByCode", value = {
            @Result(column = "count", property = "count")
    })
    int queryPromoteByCode(String promoteCode);

    //新增推广记录
    @Insert(PrePromoteSQL.SAVE_PRE_PROMOTE)
    int savePrePromote(PrePromoteSaveDTO prePromoteSaveDTO);

    //修改时查询推广记录编号是否已经存在（不包含本身）
    @Select(PrePromoteSQL.QUERY_PRE_PROMOTE_BY_CODE2)
    @Results(id = "queryPromoteByCode2", value = {
            @Result(column = "count", property = "count")
    })
    int queryPromoteByCode2(@Param("promoteCode") String promoteCode, @Param("promoteCode2") String promoteCode2);

    //修改推广记录
    @Update(PrePromoteSQL.UPDATE_PRE_PROMOTE)
    int updatePrePromote(PrePromoteUpdateDTO prePromoteUpdateDTO);

    //删除推广记录
    @Update(PrePromoteSQL.DELETE_PRE_PROMOTE)
    int deletePrePromote(PrePromoteDeleteDTO prePromoteDeleteDTO);

    //提交推广记录
    @Update(PrePromoteSQL.SUBMIT_PRE_PROMOTE)
    int submitPrePromote(PrePromoteDeleteDTO prePromoteDeleteDTO);

    //根据主键查询推广记录唯一数据
    @Select(PrePromoteSQL.QUERY_PRE_PROMOTE_BY_UID)
    @Results(id = "queryPrePromoteByUid", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "promote_code", property = "updatePromoteCode"),
            @Result(column = "info_source", property = "updateInfoSource"),
            @Result(column = "source_time", property = "updateSourceTime"),
            @Result(column = "into_company", property = "updateIntoCompany"),
            @Result(column = "client_region_", property = "updateClientRegion_"),
            @Result(column = "client_region", property = "updateClientRegion"),
            @Result(column = "client_name_", property = "updateClientName_"),
            @Result(column = "client_name", property = "updateClientName"),
            @Result(column = "contact", property = "updateContact"),
            @Result(column = "contact_person", property = "updateContactPerson"),
            @Result(column = "client_demand", property = "updateClientDemand"),
            @Result(column = "purchase_quantity", property = "updatePurchaseQuantity"),
            @Result(column = "receive_person_", property = "updateReceivePerson_"),
            @Result(column = "receive_person", property = "updateReceivePerson"),
            @Result(column = "remark", property = "updateRemark")
    })
    PrePromoteQueryVO2 queryPrePromoteByUid(String uid);

    //根据条件查询推广记录所有数据条数
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_ALL_COUNT})
    @Results(id = "queryPrePromoteAllCount", value = {
            @Result(column = "count", property = "count")
    })
    int queryPrePromoteAllCount(@Param("infoSource") String infoSource, @Param("sourceTime") String sourceTime, @Param("intoCompany") String intoCompany);

    //根据条件查询推广记录所有数据
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_ALL})
    @Results(id = "queryPrePromoteAll", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "promote_code", property = "promoteCode"),
            @Result(column = "info_source", property = "infoSource"),
            @Result(column = "source_time", property = "sourceTime"),
            @Result(column = "into_company", property = "intoCompany"),
            @Result(column = "client_region", property = "clientRegion"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "purchase_quantity", property = "purchaseQuantity"),
            @Result(column = "receive_person", property = "receivePerson"),
            @Result(column = "state", property = "state"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PrePromoteQueryVO> queryPrePromoteAll(@Param("infoSource") String infoSource, @Param("sourceTime") String sourceTime, @Param("intoCompany") String intoCompany, @Param("page") int page, @Param("limit") int limit);

    //根据条件查询推广记录所有数据条数
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_ALL_COUNT2})
    @Results(id = "queryPrePromoteAllCount2", value = {
            @Result(column = "count", property = "count")
    })
    int queryPrePromoteAllCount2(@Param("infoSource") String infoSource, @Param("sourceTime") String sourceTime, @Param("intoCompany") String intoCompany, @Param("state") String state);

    //根据条件查询推广记录所有数据
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_ALL2})
    @Results(id = "queryPrePromoteAll2", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "promote_code", property = "promoteCode"),
            @Result(column = "info_source", property = "infoSource"),
            @Result(column = "source_time", property = "sourceTime"),
            @Result(column = "into_company", property = "intoCompany"),
            @Result(column = "client_region", property = "clientRegion"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "purchase_quantity", property = "purchaseQuantity"),
            @Result(column = "receive_person", property = "receivePerson"),
            @Result(column = "state", property = "state"),
            @Result(column = "sales_manager", property = "salesManager"),
            @Result(column = "dispatch_time", property = "dispatchTime"),
            @Result(column = "sales_person", property = "salesPerson"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PrePromoteQueryVO> queryPrePromoteAll2(@Param("infoSource") String infoSource, @Param("sourceTime") String sourceTime, @Param("intoCompany") String intoCompany, @Param("state") String state, @Param("page") int page, @Param("limit") int limit);

    //根据条件查询推广记录所有数据条数
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_ALL_COUNT3})
    @Results(id = "queryPrePromoteAllCount3", value = {
            @Result(column = "count", property = "count")
    })
    int queryPrePromoteAllCount3(@Param("infoSource") String infoSource, @Param("sourceTime") String sourceTime, @Param("intoCompany") String intoCompany);

    //根据条件查询推广记录所有数据
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_ALL3})
    @Results(id = "queryPrePromoteAll3", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "promote_code", property = "promoteCode"),
            @Result(column = "info_source", property = "infoSource"),
            @Result(column = "source_time", property = "sourceTime"),
            @Result(column = "into_company", property = "intoCompany"),
            @Result(column = "client_region", property = "clientRegion"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "purchase_quantity", property = "purchaseQuantity"),
            @Result(column = "receive_person", property = "receivePerson"),
            @Result(column = "state", property = "state"),
            @Result(column = "sales_manager", property = "salesManager"),
            @Result(column = "dispatch_time", property = "dispatchTime"),
            @Result(column = "sales_person", property = "salesPerson"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<PrePromoteQueryVO> queryPrePromoteAll3(@Param("infoSource") String infoSource, @Param("sourceTime") String sourceTime, @Param("intoCompany") String intoCompany, @Param("page") int page, @Param("limit") int limit);

    //查询地区信息（临时查询，正常应该在地区接口中）
    @Select(PrePromoteSQL.QUERY_BASE_REGION_ALL)
    @Results(id = "getRegionName", value = {
            @Result(column = "objuid", property = "value"),
            @Result(column = "region_name", property = "text"),
    })
    List<PrePromoteQueryVO> getRegionName();

    //查询人员信息（临时查询，正常应该在人员接口中）
    @Select(PrePromoteSQL.QUERY_FAC_EMPLOYEE_ALL)
    @Results(id = "queryFacEmployeeNameAll", value = {
            @Result(column = "objuid", property = "value"),
            @Result(column = "emp_name", property = "text"),
    })
    List<PrePromoteQueryVO> queryFacEmployeeNameAll();

    //派工推广记录
    @Update(PrePromoteSQL.ASSIGN_PRE_PROMOTE)
    int assignPrePromote(PrePromoteUpdateDTO prePromoteUpdateDTO);

    //查询人员信息（临时查询，正常应该在人员接口中）
    @Select(PrePromoteSQL.QUERY_CRM_BASE_NAME)
    @Results(id = "queryCrmBaseName", value = {
            @Result(column = "objuid", property = "value"),
            @Result(column = "crm_name", property = "text"),
    })
    List<PrePromoteQueryVO> queryCrmBaseName();

    //查询客户联系人、联系方式信息（临时查询，正常应该在客户接口中）
    @Select(PrePromoteSQL.QUERY_CRM_BASE2)
    @Results(id = "queryCrmBase2", value = {
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "contact_number", property = "contactNumber"),
    })
    PrePromoteQueryVO queryCrmBase2(String objuid);

    //根据主键查询推广记录，用于询盘回访界面的显示
    @Select({PrePromoteSQL.QUERY_PRE_PROMOTE_BY_UID2})
    @Results(id = "queryPrePromoteByUid2", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "info_source", property = "infoSource"),
            @Result(column = "source_time", property = "sourceTime"),
            @Result(column = "into_company", property = "intoCompany"),
            @Result(column = "client_region", property = "clientRegion"),
            @Result(column = "client_name", property = "clientName"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "contact_person", property = "contactPerson"),
            @Result(column = "client_demand", property = "clientDemand"),
            @Result(column = "purchase_quantity", property = "purchaseQuantity"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    PrePromoteQueryVO queryPrePromoteByUid2(String objuid);

    //修改推广记录表人员主键
    @Update(PrePromoteSQL.UPDATE_PRE_PROMOTE_CRM_BASE)
    int updatePrePromoteCrmBase(String objuid);

}
